package com.wang.vedio.adapter.index;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vondear.rxtool.RxDeviceTool;
import com.vondear.rxtool.RxImageTool;
import com.wang.vedio.R;
import com.wang.vedio.net.entity.VideoBean;
import com.wang.vedio.net.rxjava.HttpMethods;
import com.wang.vedio.utils.TimeUtils;

import java.util.List;

/**
 * 推荐-最新 适配器
 *
 *
 * @time 2020/4/7
 */
public class SearchAdapter extends BaseQuickAdapter<VideoBean, BaseViewHolder> {
    public SearchAdapter(int layoutResId, @Nullable List<VideoBean> data) {
        super(layoutResId, data);
    }

    private int selectPosition = -1;
    public void setSelectPosition(int position){
        this.selectPosition = position;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoBean videoBean) {
        helper.setText(R.id.tv_play_count, videoBean.getPlayNum()+"次播放");
        helper.setText(R.id.tv_duration, videoBean.getVedioSeconds()+"");
        helper.setText(R.id.tv_title, videoBean.getTitle());
        helper.setText(R.id.tv_time, TimeUtils.timeParseStr(videoBean.getAddDate(),"yyyy-MM-dd"));

        helper.getView(R.id.vipTv).setVisibility("是".equals(videoBean.getSfVip())? View.VISIBLE:View.GONE);

        ImageView imageView = helper.getView(R.id.videoImg0);

        int imgWidth = (RxDeviceTool.getScreenWidth(mContext)- RxImageTool.dp2px(40))/2;
        ViewGroup.LayoutParams params = imageView.getLayoutParams();
        params.height = imgWidth*3/4;
        params.width = imgWidth;
        imageView.setLayoutParams(params);

        Glide.with(imageView)
                .load(HttpMethods.BASE_URL+videoBean.getVedioFmImg())
                .apply(RequestOptions.bitmapTransform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners(30))))
                .into(imageView);

    }
}
